<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>巡检项管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<style type="text/css">
		 .left-label {
		 	width: 120px !important
		 }
	</style>
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
    	<%--<input class="layui-input" name="searchTime" id="searchTime" placeholder="请输入时间检索" style="display: inline; width: 45%">--%>
        <input class="layui-input" name="keyword" id="keyword" placeholder="请输入工艺巡检项名称" autocomplete="off" style="display: inline; width: 170px">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">搜索</i></button>
</div>
<table class="layui-hide" id="tableList" lay-filter="tableList"></table>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add1"><i class="layui-icon layui-icon-add-1">组件浇铸巡检项新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="add2"><i class="layui-icon layui-icon-add-1">纺丝车间巡检项新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">批量删除</i></button>
	</div>
</script>
 
<script type="text/html" id="rowToolbar">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
              
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
 
<script type="text/javascript">
	layui.use(['table','layer','upload','form','laydate'], function(){
		var table = layui.table;
		var layer = layui.layer;
	    var form = layui.form;
		
		var $ = layui.jquery, active = {
			reload:function () {
				/*var searchTime = $("#searchTime").val();*/
				var keyword01 = $("#keyword").val();
				/*console.log(searchTime + ',' + keyword)*/
				table.reload('contenttable',{
					method:'get',
					where:{"keyword01":keyword01},
					page: {
						curr: 1
					}
				});
			}
		}
		$('.layui-btn').on('click', function(){
	        var type = $(this).data('type');
	        active[type] ? active[type].call(this) : '';
	    });
		table.render({
		    elem: '#tableList'
		    ,url:'${pageContext.request.contextPath }/processItem/queryProcessItem.do'
		    ,toolbar: '#toolbar'
		    ,title: '工艺巡检项'
		    ,id :'contenttable'
		    ,limits:[10,20,30]
		    ,cols: [[
		      {type: 'checkbox', fixed: 'left', },
		      {field:'', title:'序号', sort: true, type:'numbers', width: 60},
		      {field:'processItemName', title:'工艺巡检项名称'},
		      {field:'flag', title:'巡检项类别', templet: function(row){
					if(row.flag == '1'){
	  	    			return '组件浇铸巡检项';
		  	    	} else {
		  	    		return '纺丝车间巡检项';
		  	    	}
	          }},
		      {field:'standardValuePre', title:'标准值上限'},
		      {field:'standardValueEnd', title:'标准值下限'},
		      {fixed: 'right', title:'操作', toolbar: '#rowToolbar', width: 110}
		    ]],
		    page: true
		});
	  
		//头工具栏事件
		table.on('toolbar(tableList)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
		    switch(obj.event){
                //组件浇铸巡检项新增
		    	case 'add1':
			    	layer.open({
						type: 1 					//Page层类型
				  		,area: ['450px', '240px'] 	//宽  高
				  		,title: '新增'
				  		,shade: 0.6 				//遮罩透明度
				  		,maxmin: true 				//允许全屏最小化
				  		,anim: 1 					//0-6的动画形式，-1不开启
				  		,content: '<div id="addDivID">'+
				  					'<form class="layui-form" id="addFormID">'+
										'<table style="">'+
											'<tr align="center">'+
												'<td><input class="layui-hide" id="flag" name="flag" value="1"></td>'+
                            				'</tr>'+
											'<tr>'+
												'<td colspan="1"><label class="layui-form-label left-label" style="margin-top: 10px;">组件浇铸工艺巡检项名称</label></td>'+
												'<td colspan="3"><input class="layui-input" id="processItemName" name="processItemName" lay-verify="processItemName" style="margin-top: 10px; width: 200px; display: inline;">' +
													'<div class="layui-inline" style="margin-top: 5px;">'+
														'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
													'</div>'+
												'</td>'+
											'</tr>'+
											'<tr>'+
												'<td><label class="layui-form-label left-label" style="margin-top: -13px">标准值</label></td>'+
												'<td><input class="layui-input" id="standardValuePre" name="standardValuePre" lay-verify="standardValuePre" style="margin-bottom:15px; width:90px"></td>'+
							                    '<td>' +
													'<div class="layui-inline" style="margin-top: -16px;">'+
														'<font style="font-size: 24px; margin-left: 4px">~</font>'+
													'</div>'+
												'</td>'+
                                                '<td><input class="layui-input" id="standardValueEnd" name="standardValueEnd" lay-verify="standardValueEnd" style="margin-bottom:15px; width: 90px; display: inline;">' +
													'<div class="layui-inline" style="margin-top: 5px;">'+
														'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
													'</div>'+
												'</td>'+
                                            '</tr>'+
											'<tr>'+
												'<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-bottom: 20px; margin-left: 120px">提交</button></td>'+
                            					'<td colspan="2"><button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px; margin-left: 30px">重置</button></td>'+
                            				'</tr>'+
										'</table>'+
								  	'</form>'+
								  '</div>'
				  		/* ,content: $("#addDivID")
				  		,end: function(){
				  			$("#addDivID").hide();
				  		} */
					});
		      	break;
		      	//纺丝车间巡检项新增
		    	case 'add2':
			    	layer.open({
						type: 1 					//Page层类型
				  		,area: ['450px', '240px'] 	    //宽  高
				  		,title: '新增'
				  		,shade: 0.6 				//遮罩透明度
				  		,maxmin: true 				//允许全屏最小化
				  		,anim: 1 					//0-6的动画形式，-1不开启
				  		,content: '<div id="addDivID">'+
                                '<form class="layui-form" id="addFormID">'+
                                    '<table style="">'+
                                        '<tr align="center">'+
                                            '<td><input class="layui-hide" id="flag" name="flag" value="2"></td>'+
                                        '</tr>'+
                                        '<tr>'+
                                            '<td colspan="1"><label class="layui-form-label left-label" style="margin-top: 10px;">纺丝车间工艺巡检项名称</label></td>'+
                                            '<td colspan="3"><input class="layui-input" id="processItemName" name="processItemName" lay-verify="processItemName" style="margin-top: 10px; width: 200px; display: inline;">' +
												'<div class="layui-inline" style="margin-top: 5px;">'+
													'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
												'</div>'+
											'</td>'+
                                        '</tr>'+
										'<tr>'+
											'<td><label class="layui-form-label left-label" style="margin-top: -13px">标准值</label></td>'+
											'<td><input class="layui-input" id="standardValuePre" name="standardValuePre" lay-verify="standardValuePre" style="margin-bottom:15px; width:90px"></td>'+
											'<td>' +
												'<div class="layui-inline" style="margin-top: -16px;">'+
													'<font style="font-size: 24px; margin-left: 4px">~</font>'+
												'</div>'+
											'</td>'+
											'<td><input class="layui-input" id="standardValueEnd" name="standardValueEnd" lay-verify="standardValueEnd" style="margin-bottom:15px; width: 90px; display: inline;">' +
												'<div class="layui-inline" style="margin-top: 5px;">'+
													'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
												'</div>'+
											'</td>'+
										'</tr>'+
                                        '<tr>'+
                                            '<td colspan="2"><button class="layui-btn layui-btn-blue" id="subBtn" lay-submit lay-filter="addForm" style="margin-bottom: 20px; margin-left: 120px">提交</button></td>'+
                                            '<td colspan="2"><button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px; margin-left: 30px">重置</button></td>'+
                                        '</tr>'+
                                    '</table>'+
                                '</form>'+
                            '</div>'
				  		/* ,content: $("#addDivID")
				  		,end: function(){
				  			$("#addDivID").hide();
				  		} */
					});
		      	break;
		      	//批量删除
		    	case 'delete':
		        	var data = checkStatus.data;
		        	var idArr = new Array();
		        	if(data.length == 0){
		        		toastr.warning("请至少选择一条记录！");
		        	}
		        	for(var i=0;i < data.length;i++){
		        		/*alert(data[i].id)*/
						idArr[i] = data[i].id;
		        	}
                    $.ajax({
                        type:'post',
                        url:'${pageContext.request.contextPath }/processItem/deleteProcessItemById.do',
                        data:{"idArr" : idArr},
                        success:function(data){
                            layer.confirm('确定删除吗？', function(index){
                            	if(data > 0){
                                    toastrStyle();
                                    toastr.success("删除成功！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }else{
                                    toastrStyle();
                                    toastr.warning("删除失败！");
                                    setTimeout(function(){
                                        location.reload();
                                    },1000);
                                }
							});
                        }
                    });
		      	break;
		      	case 'select':
		      		/*console.log(obj)*/
		      	break;
		    };
		});
	  
		//监听行工具事件
		table.on('tool(tableList)', function(obj){
			var data = obj.data;
			//alert(data.id)
            var idArr = new Array();
			//单个删除
			if(obj.event === 'del'){
			  layer.confirm('确定删除吗？', function(index){
			    var id = obj.data.id;
			    idArr[0] = id;
			    $.ajax({
			    	type:'post',
			    	url:'${pageContext.request.contextPath }/processItem/deleteProcessItemById.do',
                    data:{"idArr" : idArr},
			    	success:function(data){
			    		if(data > 0){
                            toastrStyle();
                            toastr.success("删除成功！");
                            setTimeout(function(){
								location.reload();
                            },1000);
			    		}else{
                            toastrStyle();
                            toastr.warning("删除失败！");
                            setTimeout(function(){
								location.reload();
                            },1000);
			    		}
			    	}
			    });
			    layer.close(index);
			  });
			} else if(obj.event === 'edit'){
				layer.open({
				  type: 1 							//Page层类型
				  ,area: ['450px', '240px']			    //宽  高
				  ,title: '编辑'
				  ,shade: 0.6 						//遮罩透明度
				  ,maxmin: true 					//允许全屏最小化
				  ,anim: 1 							//0-6的动画形式，-1不开启
					,cache: true
				  ,content: '<form class="layui-form" id="editFormID">'+
                        '<table style="">'+
                            '<tr align="center">'+
                                '<td><input class="layui-hide" id="id" name="id" value="'+data.id+'"></td>'+
                            '</tr>'+
                            '<tr>'+
                                '<td colspan="1"><label class="layui-form-label left-label" style="margin-top: 20px;">工艺巡检项名称</label></td>'+
                                '<td colspan="3"><input class="layui-input" id="processItemName" name="processItemName" value="'+data.processItemName+'" lay-verify="processItemName" style="margin-top: 20px; width: 200px; display: inline;">' +
									'<div class="layui-inline" style="margin-top: 5px;">'+
										'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
									'</div>'+
								'</td>'+
                            '</tr>'+
                        	'<tr style="height: 10px"></tr>'+
							'<tr>'+
								'<td><label class="layui-form-label left-label" style="margin-top: -13px">标准值</label></td>'+
								'<td><input class="layui-input" id="standardValuePre" name="standardValuePre" value="'+data.standardValuePre+'" lay-verify="standardValuePre" style="margin-bottom:15px; width:90px"></td>'+
								'<td>' +
									'<div class="layui-inline" style="margin-top: -16px;">'+
										'<font style="font-size: 24px; margin-left: 4px">~</font>'+
									'</div>'+
								'</td>'+
								'<td><input class="layui-input" id="standardValueEnd" name="standardValueEnd" value="'+data.standardValueEnd+'" lay-verify="standardValueEnd" style="margin-bottom:15px; width: 90px; display: inline;">' +
									'<div class="layui-inline" style="margin-top: 5px;">'+
										'<font style="color:red; font-size: 24px; margin-left: 4px">*</font>'+
									'</div>'+
								'</td>'+
							'</tr>'+
                            '<tr>'+
                                '<td colspan="2"><button class="layui-btn layui-btn-blue" lay-submit lay-filter="editForm" style="margin-bottom: 20px; margin-left: 120px">提交</button></td>'+
                                '<td colspan="2"><button type="reset" class="layui-btn layui-btn-primary" style="margin-bottom: 20px; margin-left: 30px">重置</button></td>'+
                            '</tr>'+
                        '</table>'+
					'</form>'
				});
			}
		});

	    /**
         * 通用表单提交(AJAX方式)(新增)
         */
	    form.on('submit(addForm)', function (data) {
	    	$("#subBtn").attr("disabled",true);
	    	$.ajax({
				url : '${pageContext.request.contextPath}/processItem/addProcessItem.do',
                data: $("#addFormID").serialize(),
				cache : false,
				type : "post",
				}).done(
					function(res) {
						if (res > 0) {
                            toastrStyle();
                            toastr.success('新增成功！');
                            setTimeout(function(){
                                location.reload();
                            },1000);
						}
					}
				).fail(
					function(res) {
                        toastrStyle();
                        toastr.error('新增失败！');
                        setTimeout(function(){
							location.reload();
                        },1000);
					}
				)
				return false;
	    });
	    
	    /**
	     * 通用表单提交(AJAX方式)(修改)
	     */
	    form.on('submit(editForm)', function (data) {
	    	$.ajax({
				url : '${pageContext.request.contextPath}/processItem/editProcessItemById.do',
                data: $("#editFormID").serialize(),
				cache : false,
				type : "post",
				}).done(
					function(res) {
						if (res > 0) {
                            toastrStyle();
                            toastr.success('修改成功！');
							setTimeout(function(){
								location.reload();
                            },1000);
						}
					}
				).fail(
					function(res) {
                        toastrStyle();
                        toastr.error('修改失败！');
                        setTimeout(function(){
							location.reload();
                        },1000);
					}
				)
				return false;
	    });

        /**
         * 新增表单校验
         */
        form.verify({
            //value：表单的值item：表单的DOM对象
            processItemName: function(value, item){
                if(value == ''){
                    return '巡检项不能为空';
                }
            },
            standardValuePre: function(value, item){
                if(value == ''){
                    return '标准值下限不能为空';
                }
            },
            standardValueEnd: function(value, item){
                if(value == ''){
                    return '标准值上限不能为空';
                }
            }
        });

	});

	toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上

    //提示框样式
    function toastrStyle(){
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": false,
            "progressBar": false,
            "positionClass": "toast-top-center",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "5000",
            "hideDuration": "1000",
            "timeOut&quot": "100000",
            "extendedTimeOut": "0",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };
    }

</script>
</body>
</html>